﻿$("#exampleAccordion>li:nth-child(6) a").removeClass("collapsed");
$("#exampleAccordion>li:nth-child(6) ul").addClass("show");
$("#exampleAccordion>li:nth-child(6) ul>li:nth-child(2)").addClass("active");
var html = "";
html += '<label>订单状态'
html += '<select class="form-control form-control-sm" style="display:inline-block;margin-left:.5rem;margin-right:1rem;width:auto" id="district" aria-controls="dataTable" onChange="states(this)">'
html += '<option value="-1">无</option>'
html += '<option value="0">待审核</option>'
html += '<option value="1">已通过</option>'
html += '<option value="2">已取消</option>'
html += '<option value="3">待发货</option>'
html += '<option value="4">已发货</option>'
html += '<option value="5">已完成</option>'
html += '</select>'
html += '</label>'
var columns, state, table
$(function () {
    var type = getCookie('jiangjin').split("&")[3].split("=")[1];
    if (type == '07332506fa00992798c91411c89023a8') {
        columns = [{ "data": "OrderNo", render: function (value, type, row) { return '<a href="javascript:void(0)" onclick="OrderPro(&apos;' + row.OrderNo + '&apos;)">' + value + '</a>' } }, { "data": "UserName" }, { "data": "Mobile" }, { "data": "BuyType" }, { "data": "AddPC" }, { "data": "Money" }, { "data": "PV" }, { "data": "States" }, {
            "data": "MId", render: function (value, type, row) {
                if (row.State === 0) {
                    return '<a href="javascript:void(0)" class="btn btn-success btn-sm" onclick="OK(&apos;' + row.Id + '&apos;)">同意</a><a href="javascript:void(0)" class="btn btn-danger btn-sm ml-2" onclick="NO(&apos;' + row.Id + '&apos;)">取消</a>'
                } else {
                    return '<a href="javascript:void(0)" class="btn btn-success btn-sm" onclick="State(&apos;' + row.Id + '&apos;)">修改状态</a>'
                }
            }
        }]
    } else {
        columns = [{ "data": "OrderNo", render: function (value, type, row) { return '<a href="javascript:void(0)" onclick="OrderPro(&apos;' + row.OrderNo + '&apos;)">' + value + '</a>' } }, { "data": "UserName" }, { "data": "Mobile" }, { "data": "BuyType" }, { "data": "AddPC" }, { "data": "Money" }, { "data": "PV" }, { "data": "State" }]
    }
    //table = dataTables("/Order/PartialOrder", columns, true, "买家姓名,订单状态,服务中心");
    //dataTables = function (url, columns, search, sSearchPlaceholder) {
    table = $('#dataTable').dataTable({
            "sScrollX": "100%",
            "bScrollCollapse": true,
            "serverSide": true,
            "processing": true,
            "bFilter": true,
            "ordering": false,
            "stateSave": false,
            "deferRender": true,
            "stateDuration": 60 * 60 * 24,
            "pagingType": "simple_numbers",  //分页样式：simple,simple_numbers,full,full_numbers
            ajax: function (data, callback, settings) {
                //封装请求参数
                var param = {};
                param.size = data.length;//页面显示记录条数，在页面显示每页显示多少项的时候
                //param.start = data.start;//开始的记录序号
                param.index = (data.start / data.length) + 1;//当前页码
                param.key = data.search.value;
                param.state = state;
                //console.log(data);
                $.ajax({
                    type: "POST",
                    url: "/Order/PartialOrder",//
                    cache: false,  //禁用缓存
                    data: param,  //传入组装的参数
                    dataType: "json",
                    success: function (result) {
                        //setTimeout仅为测试延迟效果
                        //封装返回数据
                        var returnData = {};
                        returnData.draw = data.draw;//这里直接自行返回了draw计数器,应该由后台返回
                        returnData.recordsTotal = result.total;//返回数据全部记录
                        returnData.recordsFiltered = result.total;//后台不实现过滤功能，每次查询均视作全部结果
                        returnData.data = result.Data;//返回的数据列表
                        //console.log(returnData);
                        //调用DataTables提供的callback方法，代表数据已封装完成并传回DataTables进行渲染
                        //此时的数据需确保正确无误，异常判断应在执行此回调前自行处理完毕
                        callback(returnData);
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        layer.msg("请求服务器出错")
                    }
                });
            },
            //列表表头字段
            columns: columns,
            "oLanguage": { //国际化配置  
                "sProcessing": "正在获取数据，请稍后...",
                "sLengthMenu": "显示 _MENU_ 条",
                "sZeroRecords": "没有您要的内容",
                "sSearchPlaceholder": "买家姓名,服务中心",
                "sInfo": "从 _START_ 到  _END_ 条 总共 _TOTAL_ 条",
                "sInfoEmpty": "记录数为0",
                "sInfoFiltered": "(全部记录数 _MAX_ 条)",
                "sInfoPostFix": "",
                "sSearch": "搜索",
                "sUrl": "",
                "oPaginate": {
                    "sFirst": "第一页",
                    "sPrevious": "上一页",
                    "sNext": "下一页",
                    "sLast": "最后一页"
                }
            },
        }).api();    
    $("#dataTable_wrapper .row:last-child").addClass("mt-2");
    $("#dataTable_filter").prepend(html)
})

function states(t){
    state = $(t).val();
    table.ajax.reload();
}




//同意
function OK(id) {

	var option = {
		type: "post",
		url: "/Order/EditOrderState",
		data: { id: id, state: 1 },
		callback: SetMode
	}
	swGather.swAjax(option)

	//$.ajax({
	//	type: "post",
	//	url: "/Order/GetData",
	//	async:false,
	//	data: { id: id },
	//	success: function (result) {
	//		if (result.Code!="OK") {
	//			layer.msg(result.Msg)
	//		} else {
	//			layer.open({
	//				title: "具体细分如下",
	//				type: 1,
	//				content: result.Str
	//				, btn: ['确认', '取消']
	//				, yes: function (index, layero) {
	//					var option = {
	//						type: "post",
	//						url: "/Order/EditOrderState",
	//						data: { id: id, state: 1 },
	//						callback: SetMode
	//					}
	//					swGather.swAjax(option)
	//					//alert("ddd");
	//					//$.ajax({
	//					//	type: "post",
	//					//	url: "/Order/EditOrderState",
	//					//	data: { id: id, state: 1 },
	//					//	success: function (res) {
	//					//		if (res.Code != "OK") {
	//					//			layer.msg(res.Msg)
	//					//		}
	//					//	}
	//					//});

	//				}
	//				, btn2: function (index, layero) {
	//					//按钮【按钮二】的回调
	//					layer.close(index);
	//					//return false 开启该代码可禁止点击该按钮关闭
	//				}
	//				, cancel: function () {
	//					//右上角关闭回调
	//					layer.close(index);
	//					//return false 开启该代码可禁止点击该按钮关闭
	//				}
	//			});
	//		}

			
	//	}

	//})



	


    
}
//不同意
function NO(id) {


	layer.confirm('是否确认不同意改订单?', { icon: 3, title: '提示' }, function (index) {
		//do something
		var option = {
			type: "post",
			url: "/Order/EditOrderState",
			data: { id: id, state: 2 },
			callback: SetMode
		}
		swGather.swAjax(option)
		layer.close(index);
	});


}
//修改状态
function State(id) {
    var html = "";
    html += '<div class="card" style="border:none">'
    html += '<div class="card-body">'
    html += '<select class="form-control selectpicker" name="district" id="State">'
    html += '<option value="3">待发货</option>'
    html += '<option value="4">已发货</option>'
    html += '<option value="5">已完成</option>'
    html += '</select>'
    html += '</div>'
    html += '</div>'
    layer.open({
        type: 1,
        area: ['300px'], //宽高
        content: html,
        btn: ['确定', '取消'],
        yes: function () {
            var option = {
                type: "post",
                url: "/Order/EditOrderState",
                data: { id: id, state: $("#State").val() },
                callback: SetMode
            }
            swGather.swAjax(option);
            layer.closeAll('page');
        }
    });
}
function SetMode(data) {
    layer.alert(data.Str, {
        skin: 'layui-layer-lan',
        title: "信息提示"
        , closeBtn: 0
        , anim: 4 //动画类型
    }, function () {
        location.reload();
    });
}
//详情
function OrderPro(id) {
    layer.open({
        type: 2,
        title: '订单详情',
        shadeClose: true,
        shade: 0.8,
        area: ['40%', '80%'],
        content: '/Order/OrderPro/?id=' + id //iframe的url
    });
}